home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / alerts.c next >
Encoding:
C/C++ Source or Header  |  1998-12-02  |  4.7 KB  |  216 lines

  1. #include "intern.h"
  2. #include "INLINE.H"
  3.  
  4. #define AL_STR_ANZ    5
  5. #define AL_STR_LEN    40
  6. #define AL_BUT_ANZ    3
  7. #define AL_BUT_LEN    14
  8.  
  9. static int alert_key(OBJECT *tree, int edit_obj, int kstate, int *kreturn, int *next_obj)
  10. {
  11.     int    cont = TRUE;
  12.     int    scan;
  13.     int    but = 0;
  14.         
  15.     scan = *kreturn >> 8;
  16.     switch (scan)
  17.     {
  18.         case 0x3B :                /* F1 -> erster Button */
  19.             but = AL_BUT1;
  20.             break;
  21.         case 0x3C :                /* F2 -> zweiter Button */
  22.             but = AL_BUT2;
  23.             break;
  24.         case 0x3D :                /* F3 -> dritter Button */
  25.             but = AL_BUT3;
  26.             break;
  27.     }
  28.     if ((but != 0) && !get_flag(tree, but, HIDETREE))
  29.     {
  30.         *next_obj = but;
  31.         *kreturn = 0;            /* Lib soll Key nicht mehr auswerten. */
  32.         cont = FALSE;
  33.     }
  34.     return cont;
  35. }
  36.                 
  37. static int make_alert(int def, int undo, char *alert_str, int win)
  38. {
  39.     char    al_str[AL_STR_ANZ][AL_STR_LEN];
  40.     int    str_cnt;
  41.     char    al_btn[AL_BUT_ANZ][AL_BUT_LEN];
  42.     int    btn_cnt,    i, str_len, btn_len, h;
  43.     char    *p, str[40];
  44.         
  45.     /* erst mal alles verstecken */
  46.     for (i = 1; i <= AL_BUT3; i++)
  47.         set_flag(cf_alert_box, i, HIDETREE, TRUE);
  48.  
  49.     for (i = AL_BUT1; i <= AL_BUT3; i++)
  50.     {
  51.         set_flag(cf_alert_box, i, DEFAULT, FALSE);
  52.         set_flag(cf_alert_box, i, FLAG11, FALSE);
  53.     }
  54.     
  55.     /* damit jedes Mal zentriert wird */
  56.     cf_alert_box[0].ob_x = 0;
  57.     cf_alert_box[0].ob_y = 0;
  58.  
  59.  
  60.     /* Icon setzen */
  61.     i = AL_INFO;
  62.     switch (alert_str[1])
  63.     {
  64.         case '0' :
  65.             break;
  66.         case '1' :
  67.             i = AL_ACHT;
  68.             break;
  69.         case '2' :
  70.             i = AL_QST;
  71.             break;
  72.         case '3' :
  73.             i = AL_STOP;
  74.             break;
  75.         default:
  76.             debug("make_alert: Unbekanntes Icon: %c\n", alert_str[1]);
  77.             break;
  78.     }
  79.     if (i > 0)
  80.     {
  81.         set_flag(cf_alert_box, i, HIDETREE, FALSE);
  82.         if (win)
  83.             cf_alert_box[i].ob_y = 2 * gl_hchar;    /* 1 tiefer wegen Titel */
  84.     }
  85.  
  86.     /* Strings suchen */
  87.     p = alert_str + 4;
  88.     str_cnt = 0;
  89.     str_len = 0;
  90.     while ((*p != ']') && (str_cnt <= AL_STR4))
  91.     {
  92.         i = 0;
  93.         while ((*p != '|') && (*p != ']'))
  94.         {
  95.             str[i] = *p;
  96.             i++;
  97.             p++;
  98.             if (i >= AL_STR_LEN)
  99.                 break;
  100.         }
  101.         if (*p != ']')
  102.             p++;
  103.         str[i] = EOS;
  104.         if (strlen(str) > str_len)
  105.             str_len = (int)strlen(str);
  106.         strcpy(al_str[str_cnt], str);
  107.         str_cnt++;
  108.     }
  109.  
  110.     /* Buttons suchen */
  111.     p += 2;
  112.     btn_cnt = 0;
  113.     btn_len = 0;
  114.     while ((*p != ']') && (btn_cnt <= AL_BUT3))
  115.     {
  116.         i = 0;
  117.         while ((*p != '|') && (*p != ']'))
  118.         {
  119.             str[i] = *p;
  120.             i++;
  121.             p++;
  122.             if (i >= AL_BUT_LEN)
  123.                 break;
  124.         }
  125.         if (*p != ']')
  126.             p++;
  127.         str[i] = EOS;
  128.         if (strlen(str) > btn_len)
  129.             btn_len = (int)strlen(str);
  130.         strcpy(al_btn[btn_cnt], str);
  131.         btn_cnt++;
  132.     }
  133.     btn_len++;    /* immer ein breiter */
  134.     if (btn_len < 6)
  135.         btn_len = 6;
  136.  
  137.     /* frei + Texte + frei + Buttons + frei */
  138.     h = 1 + str_cnt + 1 + 1 + 1;
  139.     if (win)
  140.         h++;
  141.         
  142.     /* Box anpassen */
  143.     cf_alert_box[0].ob_width = cf_alert_box[AL_STR1].ob_x + gl_wchar * (str_len + 2);
  144.     /* passen die Buttons auch rein? */
  145.     i = (1 + (btn_cnt + 1) * btn_len) * gl_wchar;
  146.     if (cf_alert_box[0].ob_width < i)
  147.         cf_alert_box[0].ob_width = i;
  148.     cf_alert_box[0].ob_height = h * gl_hchar;
  149.  
  150.     /* Falls im Fenster, alles eine Zeile tiefer wegen des Titels */
  151.     if (win)
  152.         h = 1;
  153.     else
  154.         h = 0;
  155.         
  156.     /* Texte eintragen */
  157.     for (i = 0; i < str_cnt; i++)
  158.     {
  159.         set_flag(cf_alert_box, AL_STR1 + i, HIDETREE, FALSE);
  160.         set_string(cf_alert_box, AL_STR1 + i, al_str[i]);
  161.         cf_alert_box[AL_STR1 + i].ob_y = (1 + i + h) * gl_hchar;
  162.     }
  163.     
  164.     for (i = 0; i < btn_cnt; i++)
  165.     {
  166.         set_flag(cf_alert_box, AL_BUT1 + i, HIDETREE, FALSE);
  167.         set_string(cf_alert_box, AL_BUT1 + i, al_btn[i]);
  168.  
  169.         /* Position anpassen */
  170.         cf_alert_box[AL_BUT1 + i].ob_x = cf_alert_box[0].ob_width - (btn_cnt - i) * (btn_len + 2) * gl_wchar;
  171.         cf_alert_box[AL_BUT1 + i].ob_y = (1 + str_cnt + 1 + h) * gl_hchar;
  172.         /* Breite anpassen */
  173.         cf_alert_box[AL_BUT1 + i].ob_width = btn_len * gl_wchar;
  174.     }
  175.  
  176.     if ((def > 0) && (def < 4))
  177.         set_flag(cf_alert_box, AL_BUT1 + def - 1, DEFAULT, TRUE);
  178.     if ((undo > 0) && (undo < 4) && (undo != def))
  179.         set_flag(cf_alert_box, AL_BUT1 + undo - 1, FLAG11, TRUE);
  180.  
  181.     return TRUE;
  182. }
  183.  
  184. static int alert(int def, int undo, char *str, char *title, int win)
  185. {
  186.     int        ret = 0;
  187.     KEY_CB    old;
  188.     
  189.     if (make_alert(def, undo, str, win))
  190.     {
  191.         if (win && title[0] != EOS)
  192.             set_string(cf_alert_box, AL_TITLE, title);
  193.         
  194.         old = set_formdo_keycb(alert_key);
  195.         graf_mouse(ARROW, NULL);
  196.         if (win)
  197.             ret = simple_mdial(cf_alert_box, 0) & 0x7fff;
  198.         else
  199.             ret = simple_dial(cf_alert_box, 0) & 0x7fff;
  200.         set_formdo_keycb(old);
  201.         set_state(cf_alert_box, ret, SELECTED, FALSE);
  202.         ret = ret - AL_BUT1 + 1;
  203.     }
  204.     return ret;
  205. }
  206.  
  207. int do_alert(int def, int undo, char *str)
  208. {
  209.     return alert(def, undo, str, "", FALSE);
  210. }
  211.  
  212. int do_walert(int def, int undo, char *str, char *win_title)
  213. {
  214.     return alert(def, undo, str, win_title, TRUE);
  215. }
  216.